package com.demo.statemachine.d05.formStateMachine;

import com.demo.statemachine.d05.orderStateMachine.OrderEvents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

@WithStateMachine(id="formMachine")
public class FormEventConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * 初始状态
     */
    @OnTransition(target = "ZERO")
    public void zero() {
        logger.info("--- zero ---");
    }

    /**
     * Message 用于接收传递的参数
     * @param message
     */
    @OnTransition(source = "ZERO", target = "ONE")
    public void one(Message<OrderEvents> message) {
        System.out.println("传递的参数：" + message.getHeaders().get("order"));
        logger.info("--- zero to one ---");
    }


    @OnTransition(source = "ONE", target = "TWO")
    public void two(Message<OrderEvents> message) {
        System.out.println("传递的参数：" + message.getHeaders().get("order"));
        System.out.println("传递的参数：" + message.getHeaders().get("otherObj"));
        logger.info("--- one to two ---");
    }
}
